package ace.module.account.core.impl.service.impl;

import ace.module.account.api.model.input.IamAccountTagAddInput;
import ace.module.account.core.impl.dao.entity.IamAccount;
import ace.module.account.core.impl.dao.entity.IamAccountTag;
import ace.module.account.core.impl.manager.IamAccountManager;
import ace.module.account.core.impl.manager.IamAccountTagManager;
import ace.module.account.core.impl.service.IamAccountTagService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author caspar
 * @date 2023/3/18 16:16
 */
@Component
@AllArgsConstructor
public class IamAccountTagServiceImpl implements IamAccountTagService {
  private final IamAccountManager iamAccountManager;
  private final IamAccountTagManager iamAccountTagManager;

  @Transactional(rollbackFor = Exception.class)
  @Override
  public IamAccountTag addTag(IamAccountTagAddInput input) {
    IamAccount iamAccount = this.iamAccountManager.getAndCheckById(input.getAccountId());
    return iamAccountTagManager.addTag(
        iamAccount.getIamAppId(),
        input.getAccountId(),
        input.getTagType(),
        input.getTagKey(),
        input.getTagValue());
  }
}
